package com.chlorine.sandbox;

import java.util.List;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.Checkable;
import android.widget.TextView;

public class CustomArrayAdapter extends ArrayAdapter<Item> {

    Context context;

    public CustomArrayAdapter(Context context, int textViewResourceId, 
    		List<Item> objects) {
        super(context, textViewResourceId, objects);
        this.context = context;
    }

    /*private view holder class*/
    private class ViewHolder {
        TextView itemTitle;
        TextView itemDesc;
        Checkable itemBox;
    }

    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        Item item = getItem(position);

        LayoutInflater inflater = (LayoutInflater) context
                .getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
        if (convertView == null) {
            convertView = inflater.inflate(R.layout.list_item, null);
            holder = new ViewHolder();
            holder.itemTitle = (TextView) convertView.findViewById(R.id.list_item_title);
            holder.itemDesc = (TextView) convertView.findViewById(R.id.list_item_desc);
            holder.itemBox = (Checkable) convertView.findViewById(R.id.list_item_box);
            convertView.setTag(holder);
        } else
            holder = (ViewHolder) convertView.getTag();

        holder.itemTitle.setText(item.getTitle());
        holder.itemDesc.setText(item.getDesc());
        holder.itemBox.setChecked(item.getChecked());
        //holder.txtPrice.setText(String.valueOf(rowItem.getPrice()) + " TL");
        //holder.imageView.setImageResource(rowItem.getImageId());

        return convertView;
    }

}
